from django.db import models
from datetime import datetime

# Create your models here.
class User(models.Model):
	username = models.CharField(max_length=50) #员工账号
	nickname = models.CharField(max_length=50) #昵称
	password_hash = models.CharField(max_length=100)#密码
	password_salt = models.CharField(max_length=50)#密码干扰值
	status = models.IntegerField(default=1)#状态:1正常:2禁用:3删除
	create_at = models.DateTimeField(default=datetime.now)#创建时间
	update_at = models.DateTimeField(default=datetime.now)#修改时间


	def toDict(self):
		return {'id':self.id,'username':self.username,'nickname':self.nickname,'password_hash':self.password_hash,'password_salt':self.password_salt,'status':self.status,'create_at':self.create_at.strftime('%Y-%m-%d %H:%M:%S'),'update_at':self.update_at.strftime('%Y-%m-%d %H:%M:%S')}

class Shop(models.Model):
	name = models.CharField(max_length=255) #员工账号
	cover_pic = models.CharField(max_length=255) #昵称
	banner_pic = models.CharField(max_length=255)#密码
	phone = models.CharField(max_length=255)
	address = models.CharField(max_length=255)#密码干扰值
	status = models.IntegerField(default=1)#状态:1正常:2禁用:3删除
	create_at = models.DateTimeField(default=datetime.now)#创建时间
	update_at = models.DateTimeField(default=datetime.now)#修改时间

	def toDict(self):
		shopname = self.name.split('-')
		return {'id':self.id,'name':shopname[0],'shop':shopname[1],'cover_pic':self.cover_pic,'banner_pic':self.banner_pic,'address':self.address,'phone':self.phone,'status':self.status,'create_at':self.create_at.strftime('%Y-%m-%d %H:%M:%S'),'update_at':self.update_at.strftime('%Y-%m-%d %H:%M:%S')}


class Category(models.Model):
	shop_id = models.IntegerField() #员工账号
	name = models.CharField(max_length=50)#密码干扰值
	status = models.IntegerField(default=1)#状态:1正常:2禁用:3删除
	create_at = models.DateTimeField(default=datetime.now)#创建时间
	update_at = models.DateTimeField(default=datetime.now)#修改时间Category

class Product(models.Model):
	shop_id = models.IntegerField() #员工账号
	category_id = models.IntegerField() #昵称
	cover_pic = models.CharField(max_length=255)#密码
	name = models.CharField(max_length=50)
	price = models.FloatField()#密码干扰值
	status = models.IntegerField(default=1)#状态:1正常:2禁用:3删除
	create_at = models.DateTimeField(default=datetime.now)#创建时间
	update_at = models.DateTimeField(default=datetime.now)#修改时间

	def toDict(self):
		return {'id':self.id,'shop_id':self.shop_id,'category_id':self.category_id,'cover_pic':self.cover_pic,'name':self.name,'price':self.price,'status':self.status,'create_at':self.create_at.strftime('%Y-%m-%d %H:%M:%S'),'update_at':self.update_at.strftime('%Y-%m-%d %H:%M:%S')}


class Member(models.Model):
	nickname = models.CharField(max_length=50)    #昵称
	avatar = models.CharField(max_length=255)    #头像
	mobile = models.CharField(max_length=50)    #电话
	status = models.IntegerField(default=1)        #状态:1正常/2禁用/9删除
	create_at = models.DateTimeField(default=datetime.now)    #创建时间
	update_at = models.DateTimeField(default=datetime.now)    #修改时间

	def toDict(self):
		return {'id':self.id,'nickname':self.nickname,'avatar':self.avatar,'mobile':self.mobile,'status':self.status,'create_at':self.create_at.strftime('%Y-%m-%d %H:%M:%S'),'update_at':self.update_at.strftime('%Y-%m-%d %H:%M:%S')}

class Orders(models.Model):
    shop_id = models.IntegerField()   #店铺id号
    member_id = models.IntegerField() #会员id
    user_id = models.IntegerField()   #操作员id
    money = models.FloatField()     #金额
    status = models.IntegerField(default=1)   #订单状态:1过行中/2无效/3已完成
    payment_status = models.IntegerField(default=1)   #支付状态:1未支付/2已支付/3已退款
    create_at = models.DateTimeField(default=datetime.now)  #创建时间
    update_at = models.DateTimeField(default=datetime.now)  #修改时间

    


#订单详情模型
class OrderDetail(models.Model):
    order_id = models.IntegerField()  #订单id
    #product_id = models.IntegerField()  #菜品id
    product = models.ForeignKey('Product',on_delete=models.CASCADE)
    product_name = models.CharField(max_length=50) #菜品名称
    price = models.FloatField()     #单价
    quantity = models.IntegerField()  #数量
    status = models.IntegerField(default=1) #状态:1正常/9删除

    


# 支付信息模型
class Payment(models.Model):
    order_id = models.IntegerField()  #订单id号
    member_id = models.IntegerField() #会员id
    money = models.FloatField()     #支付金额
    type = models.IntegerField()      #付款方式：1会员付款/2收银收款
    bank = models.IntegerField(default=1) #收款银行渠道:1微信/2余额/3现金/4支付宝
    status = models.IntegerField(default=1) #支付状态:1未支付/2已支付/3已退款
    create_at = models.DateTimeField(default=datetime.now)  #创建时间
    update_at = models.DateTimeField(default=datetime.now)  #修改时间

    